package com.example.homework_001;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	TextView textview;
	int temp1 = 0;
	int sum = 0;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Button btn1 = (Button)findViewById(R.id.button1);
		Button btn2 = (Button)findViewById(R.id.button2);
		Button btn3 = (Button)findViewById(R.id.button3);
		Button btn4 = (Button)findViewById(R.id.button4);
		Button btn5 = (Button)findViewById(R.id.button5);
		Button btn6 = (Button)findViewById(R.id.button6);
		Button btn7 = (Button)findViewById(R.id.button7);
		Button btn8 = (Button)findViewById(R.id.button8);
		Button btn9 = (Button)findViewById(R.id.button9);
		Button plus = (Button)findViewById(R.id.button10);
		Button equal = (Button)findViewById(R.id.button11);
		
		textview = (TextView)findViewById(R.id.textView1);
		
		btn1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 1;
					
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 1;
				}
				
			}
		});
		
		btn2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 2;
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 2;
				}
				
			}
		});
		
		btn3.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 3;
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 3;
				}
				
			}
		});
		
		btn4.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 4;
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 4;
				}
				
			}
		});
		
		btn5.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 5;
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 5;
				}
				
			}
		});
		
		btn6.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 6;				
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 6;
				}
				
			}
		});
		
		btn7.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 7;
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 7;
				}
				
			}
		});
		
		btn8.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 8;
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 8;
				}
				
			}
		});
		
		btn9.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if(temp1 == 0)
				{
					temp1 = 9;
					String str = Integer.toString(temp1);
					textview.setText(str);
				}
				else
				{
					temp1 = (temp1 * 10) + 9;
				}
				
			}
		});
		
		plus.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				sum += temp1;
				temp1 = 0;
				
			}
		});
		
		equal.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				sum += temp1;
				
				String str = Integer.toString(sum);
				textview.setText(str);
				
				sum = 0;
				temp1 = 0;
				
			}
		});
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
